feat: stickies for forum posts which get posted on forum post create #384
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
feat: stickies for forum posts which get posted on forum post create
TL;DR
With the introduction of Forum Channels, there is a need for an automated message posted by the bot every time someone creates a new post. This is especially important for Support channels.
This PR introduces the possibility to configure a message for a Forum Channel that will get posted every time a Forum Post is created.
See the Video in Test Evidence for a breakdown
Description
Use Case & Requirements
With the introduction of Forum Channels, there is a need for an automated message posted by the bot every time someone creates a new post. This is especially important for Support channels.
Summary of requirements:
Solution
Instead of making a new type of message that is stored in the database, the ongoing work for stickies is re-used for this requirements.
In general, stickies are messages, configured per channel (one per channel) that get posted to the channel whenever certain conditions are met. They only get posted to the channel if a new message is posted by a user, and only when the sticky hasn't been posted in the last amount of or .
In this case, the sticky should not be posted on activity in the Forum Post, but only once on the creation of the Forum Post. Everything else is the same: The message is customizable and needs to be configured for the Forum Channel.
Implementation
Discord.js version
Because this change has to manage Forum Channels, a new version of discord.js (14.3.0+) is needed, as the currently used version (14.0.3) does not support Forum Channels (
ForumChannel
).This PR has an updated
package-lock.json
file which only hasdiscord.js
and its dependencies updated by doing annpm update discord.js
.Forum Channels and Forum Posts
ForumChannels
are in essence similar toTextChannels
, with the difference that you can't post message to them directly.However, Forum Posts are nothing more than regular Discord Threads (
ThreadChannel
). The only difference between a regularTextChannel
thread andForumChannel
thread is that the parent of theThreadChannel
refers to aForumChannel
.Sticky DB Object
A new database object has been added to introduce a sticky message. It contains the following properties:
channelId
: Contains the channel to which the message belongs. A channel can only contain a single message, so it is set to be unique.message
: The actual message contentimageUrl
: An optional URL to an image which will be included in the sticky messagetimeInterval
: Indicates the minimum time that has to have passed before a sticky can be posted again (This is not used in the Forum Post message as it only posts it on Forum Post Creation)messageCount
: Indicates the minimum amount of posts that have to be posted in the channel before a sticky can be posted again (This is not used in the Forum Post message as it only posts it on Forum Post Creation)moderator
: The moderator that last made a change to the stickyupdatedTimestamp
: The last time the sticky was updatedlastPostedId
: The ID of the message when the sticky was last posted. (This is not used in the Forum Post message as it only posts it on Forum Post Creation)Sticky Management command (
.sticky
)To manage stickies, a new command is introduced which can be executed with the
.sticky
command.This command has the following help:
It has the following sub-commands.
For all sub-commands, a channel id can optionally be provided. If it is not provided, the channel in which the
.sticky
command is executed is used as the channel to manage.set
: Configure the sticky message for a channelimage
: Configure an image for a channelcount
: Configure the minimum message counttime
: Configure the minimum time interval (This is not relevant in the Forum Post message as it only posts it on Forum Post Creation)unset
: Delete the sticky message for a channel (This is not relevant in the Forum Post message as it only posts it on Forum Post Creation)info
: Shows information about the sticky for a channelThread Create handler (Forum Post Handler)
A new handler is introduced that is executed whenever a new
ThreadChannel
is created.This handler will first check if the
ThreadChannel
is actually a Forum Post by checking if the parent of the thread is of the typeGUILD_FORUM
.If so, it will check if there's a sticky for that parent configured and post it to the Forum Post.
Note: There is no real stickies handler yet, which would be on the messageCreate event, but this code is ready & tested in another branch. It will be implemented once the bots are split and a separate Sticky bot exists. This thread create handler will also move to the sticky bot.
Test Results
Discord Username
straks#7240